\chapter{Advanced topics}
\label{sec:advanced_topics}

\section{Customization}
Each sub-step of an iteration and all direct calls can be adjusted to the user needs. The internal part of the iterative framework is organized as follows: all scripts are called using two keywords
\begin{verbatim}
  csg_call key1 key2
\end{verbatim}
For example, \texttt{csg\_call update imc} calls the \texttt{update} script for the inverse Monte Carlo procedure. The corresponding keywords are listed in \sect{sec:csg_table} or can be output directly by calling
\begin{verbatim}
  csg_call --list
\end{verbatim}

It is advised not to change already implemented scripts. To customize a script or add a new one, copy the script to your own directory (set by \cgopt{inverse.scriptpath}) and redirect its call by creating your own \texttt{csg\_table} file in this directory which looks like this
\begin{verbatim}
  key1 key2 script1 options
  key3 key4 script2
\end{verbatim}
If the local keys are already in use, the existing call will be overloaded.

As an example, we will illustrate how to overload the script which calls the sampling package. 
The \prog{csg_inverse} script runs \progex{mdrun} from the \gromacs package only on one cpu. Our task will be to change the script so that \gromacs uses 8 cpus, which is basically the same as adding mpirun options in \cgopt{inverse.gromacs.mdrun.command}.

First we find out which script calls \progex{mdrun}:
\begin{verbatim}
  csg_call --list | grep gromacs
\end{verbatim}
The output should look as follows
\begin{verbatim}
  init gromacs initalize_gromacs.sh
  prepare gromacs prepare_gromacs.sh
  run gromacs run_gromacs.sh
  pressure gromacs calc_pressure_gromacs.sh
  rdf gromacs calc_rdf_gromacs.sh
  imc_stat gromacs imc_stat_generic.sh
  convert_potential gromacs potential_to_gromacs.sh
\end{verbatim}
the third line indicates the script we need. If the output of \prog{csg_call} is not clear, one can try to find the right script in \sect{sec:csg_table}. Alternatively, check the folder
\begin{verbatim}
  <csg-installation>/share/scripts/inverse
\end{verbatim}
for all available scripts. 

Analyzing the output of
\begin{verbatim}
  csg_call --cat run gromacs
\end{verbatim}
we can conclude that this is indeed the script we need as the content (in shorted form is):
%
\begin{verbatim}
  critical mdrun
\end{verbatim}
Now we can create our own \texttt{SCRIPTDIR}, add a new script there, make it executable and overload the call of the script:
\begin{verbatim}
  mkdir -p SCRIPTDIR
  cp `csg_call --quiet --show run gromacs` SCRIPTDIR/my_run_gromacs.sh
  chmod 755 SCRIPTDIR/my_run_gromacs.sh
  echo "run gromacs my_run_gromacs.sh" >> SCRIPTDIR/csg_table
\end{verbatim}
Please note that \texttt{my\_run\_gromacs.sh} is the name of the script and \texttt{SCRIPTDIR} is the custom script directory, which can be a global or a local path.
Now we change the last line of \texttt{my\_run\_gromacs.sh} to:
\begin{verbatim}
  critical mpirun -np 8 mdrun
\end{verbatim}
This completes the customization. Do not forget to add \texttt{SCRIPTDIR} to \cgopt{inverse.scriptpath} in the setting \xml file (see \sect{sec:ref_options}).

You can check the new script by running:
\begin{verbatim}
  csg_call --scriptdir SCRIPTDIR --list
  csg_call --scriptdir SCRIPTDIR --run run gromacs
\end{verbatim}

Finally, do not forget to remove the license infomation and change the version number of the script.

\section{Used external packages}

\subsection{GroMaCS}
\label{progpack.gromacs}
Get it from \htmladdnormallink{www.gromacs.org}{http://www.gromacs.org}
\begin{itemize}
\item \hypertarget{progex.mdrun}{\textbf{mdrun}}
\item \hypertarget{progex.grompp}{\textbf{grompp}}
\end{itemize}

\subsection{ESPResSo}
\label{progpack.espresso}
Get it from \htmladdnormallink{www.espressomd.org}{http://www.espressomd.org}

\subsection{Gnuplot}
\label{progpack.gnuplot}
Get it from \htmladdnormallink{www.gnuplot.info}{http://www.gnuplot.info}

\subsection{GNU Octave}
\label{progpack.octave}
Get it from \htmladdnormallink{www.gnu.org}{http://www.gnu.org/software/octave/}

\subsection{LAMMPS}
\label{progpack.lammps}
Get it from \htmladdnormallink{lammps.sandia.gov}{http://lammps.sandia.gov/}

\subsection{Matlab}
\label{progpack.matlab}
Get it from \htmladdnormallink{www.mathworks.com}{http://www.mathworks.com/products/matlab/}

\subsection{NumPy}
\label{progpack.numpy}
Get it from \htmladdnormallink{http://numpy.scipy.org}{http://numpy.scipy.org}
